package coolq.yaozhenyong.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.forte.qqrobot.anno.Filter;
import com.forte.qqrobot.anno.Listen;
import com.forte.qqrobot.anno.depend.Beans;
import com.forte.qqrobot.beans.messages.msgget.GroupMsg;
import com.forte.qqrobot.beans.messages.types.MsgGetTypes;

import coolq.yaozhenyong.bean.BoobleansGroup;
import coolq.yaozhenyong.bean.QqGroupRecord;
import coolq.yaozhenyong.custom.QqAndHtml;
import coolq.yaozhenyong.custom.SpringContextUtil;
import coolq.yaozhenyong.service.BoobleansGroupService;
import coolq.yaozhenyong.service.QqGroupRecordService;
@Beans
@Listen(MsgGetTypes.groupMsg)
public class MyGroupRecordController {
	
	/***
	 * 此处监听所有群消息，并保存群聊天记录
	 */
	@Filter
	public void savegrouprecord(GroupMsg msg) {
		/** 查询是否需要监听状态 **/
		BoobleansGroupService bean = SpringContextUtil.getBean(BoobleansGroupService.class);
		BoobleansGroup byId = bean.getById(1);
		if(byId.getBooleanok().equals("开启")) {
			QqGroupRecordService bean2 = SpringContextUtil.getBean(QqGroupRecordService.class);
			QqGroupRecord qqgroup = new QqGroupRecord();
			qqgroup.setMsg(QqAndHtml.getMsghtml(msg.getMsg()));
			qqgroup.setType(msg.getFont());
			qqgroup.setQunnumber(msg.getGroup());
			qqgroup.setQqnumber(msg.getQQ());
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			qqgroup.setTime(df.format(new Date()));
			bean2.save(qqgroup);
		}
	}
	
}
